class Solution:
    def threeSum(self, nums: list[int]) -> list[list[int]]:
        nums.sort()
        data={}
        res=[]
        for i in range(len(nums)):
            #记下所有元素的最大值
            data[nums[i]]=i
        set1:set=set()
        for i in range(len(nums)-2):
            if nums[i] in set1:
                continue
            set1.add(nums[i])
            set2=set()
            for j in range(i+1,len(nums)-1):
                if nums[j] in set2:
                    continue
                set2.add(nums[j])
                target=-(nums[i]+nums[j])
                if target in data.keys() and data[target]>j:
                    res.append([nums[i],nums[j],target])
        return res
